<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/** @see Zead_Html_Helper_Abstract **/
require_once 'Zead/Html/Helper/Abstract.php';

/**
 * @category   Zead
 * @package    Zead_Html
 * @subpackage Zead_Html_Helper
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License  
 */
class Zead_Html_Helper_HeadTitle extends Zead_Html_Helper_Abstract 
{
	/** @var string **/
	protected $_separator = '>';
	
	/** @var array **/
	protected $_title = array();
	
	/**
	 * Executando o helper. Como os atributos podem ser variados e ser uma ordem
	 * de obrigatoriedade e com diferentes funções assumidas, então os atributos
	 * podem ser passados em qualquer ordem.
	 *
	 * @param array $attributes
	 */
	public function headTitle($title, $setType = 'set', $separator = ' » ') 
	{
		if ($setType == 'set') {
			$this->_title[] = $title;			
		} else if ($setType == 'append') {
				$this->_title[] = $title;		
		} else if ($setType == 'prepend') {
			array_unshift($this->_title, $title);	
		}
		// Sets separator
		$this->_separator = $separator;
		
		// Criando o elemento, ser for necessário
		$title = join($this->_separator, $this->_title);
		
		if (!($element = $this->html->documentElement->select('title')->current())) {
			$element = $this->html->head()->appendChild($this->html->createElement('title'));
		}
		// Atualizando
		$element->nodeValue = $title;
	}
}
